package cn.hefan.web.servlet.task;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

import cn.hefan.domain.Task;
import cn.hefan.service.TaskService;

public class SelectTaskServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String divide = request.getParameter("divide");
		List<Task> tasks =null;
		if(divide==null||divide.length()<=0) {
			tasks = TaskService.selectTask();
		}else {
			tasks = TaskService.selectTask(divide);
		}
		
		//将信息写回客户端
		ObjectMapper mapper = new ObjectMapper();
		response.setContentType("application/json;charset=utf-8");
		mapper.writeValue(response.getOutputStream(), tasks);
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

}